//
//  RCTranlistDataModel.m
//  RocketProject
//
//  Created by chen jiedan on 13-11-28.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCTranlistDataModel.h"
#import "TravelException.h"
#import "KFObjectExtension.h"


@implementation RCTrainItemDataModel

//@synthesize dateTime = _dateTime;
//@synthesize score   = _score;
//@synthesize event = _event;
//@synthesize mobile   = _mobile;
//@synthesize dateTime = _dateTime;
//@synthesize content  = _content;
//@synthesize price    = _price;

- (void) dealloc
{
    
    self.traincode = nil;
    self.trainid = nil;
    self.trainname = nil;
    self.startcity = nil;
    self.starttime = nil;
    self.endcity = nil;
    self.endtime = nil;
    self.coattime = nil;
    self.ticketprice = nil;
    self.ticketname = nil;
    [super dealloc];
}

@end


@implementation RCTranlistDataModel


// 将JSON数据解析为数据模型
-(id) parseDataFromJSON:(NSDictionary*)data
{
    // 输入参数判断
    if ( nil == data )
        return nil;
    
    // 分配数据模型对象内存
    RCTranlistDataModel *retObject = nil;
    retObject = [[RCTranlistDataModel alloc] init];
    if ( nil == retObject )
        return retObject;
    
    NSMutableArray *listItems = [[NSMutableArray alloc] init];
    
    NSDictionary *dataDic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    retObject.pn     = [dataDic intValueForKey:@"pn" defaultValue:0];
    retObject.rn     = [dataDic intValueForKey:@"rn" defaultValue:0];
    retObject.total  = [dataDic intValueForKey:@"total" defaultValue:0];

    
    NSArray *dataItems = [dataDic arrayValueForKey:@"list" defaultValue:nil];
    if (nil == dataItems) {
        dataItems = [dataDic arrayValueForKey:@"items" defaultValue:nil];
    }
    for (NSDictionary *dic in dataItems) {
        RCTrainItemDataModel *item = [[RCTrainItemDataModel alloc] init];
        item.trainid = [dic stringValueForKey:@"trainid" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.starttime = [dic stringValueForKey:@"starttime" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.endtime = [dic stringValueForKey:@"endtime" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.trainname = [dic stringValueForKey:@"trainname" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.traincode = [dic stringValueForKey:@"traincode" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.startcity = [dic stringValueForKey:@"startcity" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.endcity = [dic stringValueForKey:@"endcity" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.coattime = [dic stringValueForKey:@"coattime" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.ticketname = [dic stringValueForKey:@"ticketname" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.ticketprice = [dic stringValueForKey:@"ticketprice" defaultValue:@"" operation:NSStringOperationTypeNone];
        [listItems addObject:item];
        [item release];
    }
    retObject.listItems = listItems;
    [listItems release];
    
    // 返回结果数据模型
    return [retObject autorelease];
}

@end


#pragma mark Plane @@@@@*************@@@@@@@@@

@implementation RCPlaneItemDataModel

//@synthesize dateTime = _dateTime;
//@synthesize score   = _score;
//@synthesize event = _event;
//@synthesize mobile   = _mobile;
//@synthesize dateTime = _dateTime;
//@synthesize content  = _content;
//@synthesize price    = _price;

- (void) dealloc
{
    
    self.time = nil;
    self.airportName = nil;
    self.planeinfo = nil;
    self.price = nil;
    self.airportFee = nil;
    self.fuelFee = nil;

    [super dealloc];
}

@end


@implementation RCPlanelistDataModel


// 将JSON数据解析为数据模型
-(id) parseDataFromJSON:(NSDictionary*)data
{
    // 输入参数判断
    if ( nil == data )
        return nil;
    
    // 分配数据模型对象内存
    RCPlanelistDataModel *retObject = nil;
    retObject = [[RCPlanelistDataModel alloc] init];
    if ( nil == retObject )
        return retObject;
    
    NSMutableArray *listItems = [[NSMutableArray alloc] init];
    
    NSDictionary *dataDic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    retObject.pn     = [dataDic intValueForKey:@"pn" defaultValue:0];
    retObject.rn     = [dataDic intValueForKey:@"rn" defaultValue:0];
    retObject.total  = [data intValueForKey:@"total_go" defaultValue:0];
    
    
    NSArray *dataItems = [dataDic arrayValueForKey:@"list" defaultValue:nil];
    if (nil == dataItems) {
        dataItems = [dataDic arrayValueForKey:@"items" defaultValue:nil];
    }
    for (NSDictionary *dic in dataItems) {
        RCPlaneItemDataModel *item = [[RCPlaneItemDataModel alloc] init];
        item.time = [dic stringValueForKey:@"time_go" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.airportName = [dic stringValueForKey:@"airportName_go" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.planeinfo = [dic stringValueForKey:@"planeinfo_go" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.price = [dic stringValueForKey:@"price_go" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.airportFee = [dic stringValueForKey:@"airportfee" defaultValue:nil operation:NSStringOperationTypeTrim];
        item.fuelFee = [dic stringValueForKey:@"fuelfee" defaultValue:nil operation:NSStringOperationTypeTrim];
        
        [listItems addObject:item];
        [item release];
    }
    retObject.listItems = listItems;
    [listItems release];
    
    // 返回结果数据模型
    return [retObject autorelease];
}

@end
